import React from 'react';
import { View, Text} from 'react-native';
import {Picker} from '@react-native-community/picker'
export default class PickTest extends React.Component{
  constructor(props){
    super();
    this.state={
      language :'java'
    }
  }

    getPicker() {
        return (
         <View>
                <Picker
                  selectedValue={this.state.language}
                  style={{ height: 50, width: 100 }}
                  onValueChange={
                    (itemValue, itemIndex) => {
                      console.log('原有值为', this.state.language, '选择了', itemValue)
                      this.setState({
                        language :itemValue
                      })
             
          
                    }
                  }
                >
                  <Picker.Item label="Java" value="java" />
                  <Picker.Item label="JavaScript" value="js" />
                </Picker>
                <Text>{this.state.language}</Text>
              </View>
        );
      }

    render(){

        return(
            <View>
        {this.getPicker()} 
            </View>
     
            
        );
    }
}